
import api from '@/api'

const actions = {
    /**
     * 获取登录信息actions
     * @param {*} params username password type 1学生 2教职工
     */
    async userlogin({commit}, params) {
        let loginInfo = await api.login(params)
        return loginInfo
    },
    /**
     * 登录
     * @param {Vm} Vm vue对象
     * @param {stirng} key_id
     * @param {string | number} type 1学生 2教职工
     */
    async login({state}, params) {
        let isMobile = params.Vm.$cjc.browser.versions.mobile
        if (isMobile) {
            // 调用JS-API登录
            await params.Vm.$cjc.apiLogin({
                appKey: '0000',
                success: (data) => { // 执行成功回调
                    params.Vm.$cjc.cjcLog('getlogin success' + data)
                },
                fail: (data) => { // 执行失败回调 只要是失败 不论是执行失败还是返回值是失败都会进fail
                    params.Vm.$cjc.cjcLog('getlogin fail' + data)
                }
            })
            params.Vm.$cjc.hiddenNavigation()
            let userInfo = await params.Vm.$cjc.apiGetUserInfor()
            return userInfo
        } else {
            if (state.development) {
                let userInfo = await params.Vm.$store.dispatch('userlogin', {
                    'username': params.username,
                    'password': params.password,
                    'type': params.type,
                    version_code: 20,
                    version_name: '1.1.2',
                    client_type: 1
                })
                return userInfo
            }
        }
    },
    /**
     * 获取客户端ip
     */
    async getClientIp({ commit }) {
        let clientIp = await api.getClientIp()
        return clientIp
    },
    /**
     * 获取客户端ip和uuid
     */
    async getClientInfo({ commit }) {
        let clientInfo = await api.getClientInfo()
        return clientInfo
    }
}

export default actions
